<?xml version="1.0" ?>

<xsl:stylesheet   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
						xmlns:lzc="http://schemas.icitadel.com/Lazarus/Compiled.xsd"
                  version="1.0">

   <xsl:output method="text"/>

	<xsl:include href="../../common.xsl" />
	<xsl:include href="../../convert.xsl" />
   
   <xsl:template match="lzc:project">
		<xsl:for-each select="lzc:table/lzc:table[ lzc:permissions/lzc:permission ]">
			<xsl:variable name="TABLE_NAME" select="concat( 'tbl', @name )" />
			<xsl:text>-- ** Granting Permissions for Table '</xsl:text><xsl:value-of select="$TABLE_NAME" /><xsl:text>'

</xsl:text>
			<xsl:for-each select="lzc:permissions/lzc:permission">
			<xsl:text>-- * Granting Permissions for Role '</xsl:text><xsl:value-of select="@role" /><xsl:text>'
GRANT </xsl:text>
				<xsl:for-each select="lzc:capabilities/lzc:capability">
					<xsl:value-of select="@name" />
					<xsl:if test="position() &lt; count( ../lzc:capability )">
						<xsl:text>, </xsl:text>
					</xsl:if>
				</xsl:for-each>
				<xsl:text> ON [</xsl:text>
				<xsl:value-of select="$TABLE_NAME" />
				<xsl:text>] TO </xsl:text>
				<xsl:value-of select="@role" />
				<xsl:text>
</xsl:text>
			</xsl:for-each>
			<xsl:text>

</xsl:text>
		</xsl:for-each>
   </xsl:template>

</xsl:stylesheet>